/*
 *  This file is part of WWWPal.
 *
 *  Copyright (C) 2003  Dr. John Punin, Department of Computer Science
 *  Rensselaer Polytechnic Institute
 *
 *  WWWPal is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  WWWPal is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 *  This file is part of WWWPal.
 *
 *  Copyright (C) 2003  Dr. John Punin, Department of Computer Science
 *  Rensselaer Polytechnic Institute
 *
 *  WWWPal is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  WWWPal is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include "LOGR_user_graph.h"
#include "LOGR_functions.h"

WebUgraphPtr
new_web_ugraph_node(void)
{
  WebUgraphPtr ugn = (WebUgraphPtr)calloc(1, sizeof(WebUgraphStruct));
  if(!ugn) {
      fprintf(stderr,"Out of Memory new_web_ugraph_node\n");
      abort();
  }
  ugn->lusers = init_linked_list();
  ugn->lpaths = init_linked_list();
  ugn->naccesses = 1;
  return ugn;
}

void
delete_web_ugraph_node(WebUgraphPtr ugn)
{	
    if(!ugn) return;
    if(ugn->lusers)
	Delete_all_list(ugn->lusers); 
    if(ugn->lpaths)
	Delete_all_list(ugn->lpaths); 
    free(ugn); ugn = NULL;
}

void
LOGR_set_ugraph_naccesses(WebUgraphPtr ugn,long num)
{
  if(!ugn) return;
  ugn->naccesses = num;
}

void
LOGR_inc_ugraph_naccesses(WebUgraphPtr ugn)
{
  if(!ugn) return;
  ugn->naccesses++;
}

long
LOGR_get_ugraph_naccesses(WebUgraphPtr ugn)
{
  if(!ugn) return 0;
  return ugn->naccesses;
}

void
LOGR_set_ugraph_info(WebUgraphPtr ugn,void * info)
{
  if(!ugn) return;
  ugn->info = info;
}

void *
LOGR_get_ugraph_info(WebUgraphPtr ugn)
{
  if(!ugn) return 0;
  return ugn->info;
}

void
LOGR_set_ugraph_lusers(WebUgraphPtr ugn,LNode_type * lusers)
{
  if(!ugn) return;
  ugn->lusers = lusers;
}

void
LOGR_add_ugraph_user(WebUgraphPtr ugn,void *user)
{
  if(!ugn) return;
  if(ugn->lusers)
      Insert_linked_list(ugn->lusers,create_new_node_llist((char *)user));   

}

LNode_type *
LOGR_get_ugraph_lusers(WebUgraphPtr ugn)
{
  if(!ugn) return 0;
  return ugn->lusers;
}

void
LOGR_set_ugraph_lpaths(WebUgraphPtr ugn,LNode_type * lpaths)
{
  if(!ugn) return;
  ugn->lpaths = lpaths;
}

void
LOGR_add_ugraph_path(WebUgraphPtr ugn,void *path)
{
  if(!ugn) return;
  if(ugn->lpaths)
      Insert_linked_list(ugn->lpaths,create_new_node_llist((char *)path));   
}

LNode_type *
LOGR_get_ugraph_lpaths(WebUgraphPtr ugn)
{
  if(!ugn) return 0;
  return ugn->lpaths;
}

int
LOGR_is_ugraph_access_lower(WebUgraphPtr u, WebUgraphPtr v)
{
  return (u->naccesses < v->naccesses);
}

int
LOGR_is_ugraph_access_bigger(WebUgraphPtr u,WebUgraphPtr v)
{
  return(u->naccesses > v->naccesses);
}

int
LOGR_is_ugraph_number_edges_lower(WebUgraphPtr u, WebUgraphPtr v)
{
  int cu = LOGR_get_ugraph_number_edges(u);
  int cv = LOGR_get_ugraph_number_edges(v);
  return (cu < cv);
}

int
LOGR_is_ugraph_number_edges_bigger(WebUgraphPtr u,WebUgraphPtr v)
{
  int cu = LOGR_get_ugraph_number_edges(u);
  int cv = LOGR_get_ugraph_number_edges(v);
  return (cu > cv);  
}

int 
LOGR_get_ugraph_number_edges(WebUgraphPtr usn)
{
    if(!usn || !usn->info)
	return 0;
    return LOGR_get_number_edges(usn->info);
}


void *
LOGR_get_ugraph_gen_edge(WebUgraphPtr usn,int j)
{
    if(!usn || !usn->info)
	return NULL;
    return (void *)LOGR_get_gen_edge_i(usn->info,j);
}

int 
LOGR_get_ugraph_num_users(WebUgraphPtr usn)
{
    if(!usn)
	return 0;
    if(!usn->lusers)
	return 0;
    return(count_llist(usn->lusers));
}


